package com.csscis.ssm.web.service.impl;

import com.csscis.ssm.core.generic.GenericDao;
import com.csscis.ssm.core.generic.GenericServiceImpl;
import com.csscis.ssm.core.util.AvailableEnum;
import com.csscis.ssm.web.dao.ValveTableMapper;
import com.csscis.ssm.web.model.ValveTable;
import com.csscis.ssm.web.service.ValveTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.UUID;

@Service
public class ValveTableServiceImpl extends GenericServiceImpl<ValveTable, Long> implements ValveTableService {

    @Autowired
    private ValveTableMapper valveTableMapper;

    @Override
    public GenericDao<ValveTable, Long> getDao() {

        return valveTableMapper;
    }

    @Override
    public List<ValveTable> selectAll(ValveTable valveTable) {

        return valveTableMapper.selectAll(valveTable);
    }

    @Override
    public int insert(ValveTable model, HttpServletRequest request) {

        model.setValveId(UUID.randomUUID().toString());
        return super.insert(model);
    }

    @Override
    public List<ValveTable> selectAllByEnabled() {

        ValveTable model = new ValveTable();
        model.setEnabled(AvailableEnum.Enable.getType());
        return valveTableMapper.selectAll(model);
    }
}
